<?php
/**
 * 获得用户信息动作类
 * @author yaoli<yaoli@pateo.com.cn>
 * @version 1.0 GetUser add by yaoli<yaoli@pateo.com.cn> 
 */
class point extends ActionBase {
	
	private $date = null;
	
	function init() {
		$this->date ['page'] = (isset ( $_REQUEST ['page'] )) ? ($_REQUEST ['page'] - 1) : 0;
		
	
	}
	
	/**
	 * 动作
	 *
	 * @see AActionBase::action()
	 */
	public function action() {
		$this->date ['point'] = load_model ( 'point' )->getPoint ( $this->date ['page'],array('action!'=>'delete') );
		
		$this->date ['count'] = load_model ( 'point' )->getRcount ( array('action!'=>'delete'));
		
		$this->date ['pagecontent'] = fenye ( url ( 'point/action' ) . "&page=", $this->date ['page'] + 1, $this->date ['count'], PERPAGE );
		
		$this->template ();
		$this->template->assign ( $this->date );
		$this->template->display ( 'point.html' );
	}
	
	//添加风景点
	public function add() {
		if (isset ( $_REQUEST ['data'] )) {
			$_REQUEST ['data'] ['create_time'] = time ();
			$_REQUEST ['data']['action'] = 'create';
			load_model ( 'point' )->replaceTable ( array ('data' => $_REQUEST ['data'] ) );
			$URL = url ( 'point/index' );
			header ( "Location: $URL" );
			exit ();
		} else {
			
			$this->template ();
			$this->template->assign ( $this->date );
			$this->template->display ( 'point_add.html' );
		}
	}
	
	//修改风景点
	public function modify() {
		
		if (isset ( $_REQUEST ['data'] )) {
			$_REQUEST ['data']['action'] = 'update';
			load_model ( 'point' )->replaceTable ( array ('data' => $_REQUEST ['data'] ) );
			$URL = $_SERVER ['HTTP_REFERER'];
			header ( "Location: $URL" );
			exit ();
		} elseif (isset ( $_REQUEST ['point_id'] )) {
			$point = load_model ( 'point' )->getTable ( array ('point_id' => $_REQUEST ['point_id'] ) );
			$this->date ['point'] = $point [0];
			$this->template ();
			$this->template->assign ( $this->date );
			$this->template->display ( 'point_modify.html' );
		} else {
			$this->template ();
			$this->template->assign ( $this->date );
			$this->template->display ( 'point_add.html' );
		}
	}
	
	// 除景点
	public function del() {
		load_model ( 'point' )->delTable ( array ('point_id' => $_REQUEST ['point_id'] ) );
	/* 	load_model('roadbook_point')->delTable(array('point_id'=>$_REQUEST['point_id']));
		 $pics = load_model('pic')->getTable ( array ('type'=>'point','id' => $_REQUEST ['point_id'] ),100 );
		load_model('pic')->delTable ( array ('type'=>'point','id' => $_REQUEST ['point_id'] ));
                foreach($pics as $key=>$value){
                        @unlink('.'.$value['url']);
                } */
		$URL = $_SERVER ['HTTP_REFERER'];
		header ( "Location: $URL" );
		exit ();
	}

}
